package com.cybertron.ironhide.manage.util;

import java.io.Serializable;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.subject.WebSubject;

import com.cybertron.ironhide.manage.domain.User;

public class SubjectUtil {

	public static User getSubject() {
		WebSubject subject = (WebSubject) SecurityUtils.getSubject();
		if (subject == null) {
			return null;
		}
		Object principal = subject.getPrincipal();
		if (principal == null || !(principal instanceof User)) {
			return null;
		} else {
			return (User) principal;
		}
	}

	public static Serializable getSessionId() {
		Serializable id = SecurityUtils.getSubject().getSession().getId();
		return id;
	}

	public static void logout() {
		WebSubject subject = (WebSubject) SecurityUtils.getSubject();
		subject.logout();
	}
}
